﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RconLibrary
{
    /// <summary>
    /// Extension functions.
    /// </summary>
    internal static class Extensions
    {
        /// <summary>
        /// Gets a slice of an array.
        /// </summary>
        /// <typeparam name="T">Working type.</typeparam>
        /// <param name="data">Array buffer.</param>
        /// <param name="index">Starting index.</param>
        /// <param name="length">Number of items.</param>
        /// <returns></returns>
        internal static T[] Slice<T>(this T[] data, int index, int length)
        {
            T[] result = new T[length];
            Array.Copy(data, index, result, 0, length);
            return result;
        }

        /// <summary>
        /// Checks if an object is a string value.
        /// </summary>
        /// <param name="value">Object</param>
        /// <returns>True if its a string.</returns>
        internal static bool IsString(this object value)
        {
            if (value is string) return true;
            return false;
        }

        /// <summary>
        /// Checks if an object is a boolean value.
        /// </summary>
        /// <param name="value">Object</param>
        /// <returns>True if its a boolean.</returns>
        internal static bool IsBoolean(this object value)
        {
            if (value is bool) return true;
            return false;
        }

        /// <summary>
        /// Check if an object is a number of any type.
        /// </summary>
        /// <param name="value">Object</param>
        /// <returns>True if its a number.</returns>
        internal static bool IsNumber(this object value)
        {
            if (value is sbyte) return true;
            if (value is byte) return true;
            if (value is short) return true;
            if (value is ushort) return true;
            if (value is int) return true;
            if (value is uint) return true;
            if (value is long) return true;
            if (value is ulong) return true;
            if (value is float) return true;
            if (value is double) return true;
            if (value is decimal) return true;
            return false;
        }
    }
}
